package com.neusoft.elmboot.controller;

import java.util.List;

import com.neusoft.elmboot.mapper.BusinessMapper;
import com.neusoft.elmboot.po.BusinessVO;
import com.neusoft.elmboot.util.APIResponse;
import com.neusoft.elmboot.util.ErrorCode;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.service.BusinessService;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Business")
public class BusinessController {

	@Resource
	private BusinessService businessService;

	@GetMapping("/list")
	public APIResponse listBusinessByOrderTypeId(int orderTypeId ) throws Exception {
		return APIResponse.success(businessService.listBusinessByOrderTypeId(orderTypeId)) ;
	}

	@GetMapping("/list/rating")
	public APIResponse listBusinessOrderByRating(){
		return APIResponse.success(businessService.listBusinessOrderByRating());
	}

	@GetMapping("/list/saleVolume")
	public APIResponse listBusinessOrderBySaleVolume(){
		return APIResponse.success(businessService.listBusinessOrderBySaleVolume());
	}

	@PostMapping
	public APIResponse add(BusinessVO businessVO){
		return APIResponse.success(businessService.addBusiness(businessVO));
	}

	@PutMapping
	public APIResponse update(BusinessVO businessVO){
		return APIResponse.success(businessService.update(businessVO));
	}


	@GetMapping
	public APIResponse getBusinessById(int businessId) throws Exception {
		return APIResponse.success(businessService.getBusinessById(businessId));
	}


	@DeleteMapping
	public APIResponse delete(Integer id){
		try {
			return APIResponse.success(businessService.delete(id));
		}catch (Exception e){
			return APIResponse.error(ErrorCode.ERROR,"商户不存在");
		}
	}


	@GetMapping("/all")
	public APIResponse getList(){
		try {
			return APIResponse.success(businessService.list());
		}catch (Exception e){
			return APIResponse.error(ErrorCode.ERROR);
		}
	}
}
